package com.smart.community.commons.websocket;

import lombok.Data;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * WebSocket消息基类
 * 
 * @author Wu.Liang
 * @since 2025-01-30
 */
@Data
public abstract class WebSocketMessage implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 消息ID
     */
    private String messageId;

    /**
     * 消息类型
     */
    private String messageType;

    /**
     * 发送者ID
     */
    private Long senderId;

    /**
     * 发送者名称
     */
    private String senderName;

    /**
     * 接收者ID（可选，用于点对点消息）
     */
    private Long receiverId;

    /**
     * 目标房间/频道
     */
    private String targetRoom;

    /**
     * 消息内容
     */
    private Object content;

    /**
     * 消息时间戳
     */
    private LocalDateTime timestamp;

    /**
     * 消息状态：PENDING-待发送，SENT-已发送，DELIVERED-已送达，READ-已读
     */
    private String status;

    /**
     * 扩展属性
     */
    private Object extensions;

    /**
     * 构造函数
     */
    public WebSocketMessage() {
        this.messageId = java.util.UUID.randomUUID().toString();
        this.timestamp = LocalDateTime.now();
        this.status = "PENDING";
    }

    /**
     * 构造函数
     * 
     * @param messageType 消息类型
     * @param content 消息内容
     */
    public WebSocketMessage(String messageType, Object content) {
        this();
        this.messageType = messageType;
        this.content = content;
    }

    /**
     * 设置发送者ID
     * 
     * @param senderId 发送者ID
     */
    public void setSenderId(Long senderId) {
        this.senderId = senderId;
    }
    
    /**
     * 设置发送者名称
     * 
     * @param senderName 发送者名称
     */
    public void setSenderName(String senderName) {
        this.senderName = senderName;
    }
    
    /**
     * 消息状态枚举
     */
    public static class MessageStatus {
        public static final String PENDING = "PENDING";     // 待发送
        public static final String SENT = "SENT";           // 已发送
        public static final String DELIVERED = "DELIVERED"; // 已送达
        public static final String READ = "READ";           // 已读
        public static final String FAILED = "FAILED";       // 发送失败
    }
}
